package com.rolerealm.domain.enums;

import lombok.Getter;

/**
 * 消息发送者类型枚举
 * 
 * @author RoleRealm Team
 * @version 1.0.0
 */
@Getter
public enum SenderType {
    
    /**
     * 用户发送的消息
     */
    USER(1, "user", "用户"),
    
    /**
     * AI发送的消息
     */
    AI(2, "ai", "AI");
    
    /**
     * 数据库存储值
     */
    private final Integer code;
    
    /**
     * 字符串标识
     */
    private final String value;
    
    /**
     * 描述
     */
    private final String description;
    
    SenderType(Integer code, String value, String description) {
        this.code = code;
        this.value = value;
        this.description = description;
    }
    
    /**
     * 根据字符串值获取枚举
     * 
     * @param value 字符串值
     * @return 对应的枚举
     */
    public static SenderType fromValue(String value) {
        for (SenderType type : values()) {
            if (type.value.equals(value)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown sender type: " + value);
    }
    
    /**
     * 根据数据库代码获取枚举
     * 
     * @param code 数据库代码
     * @return 对应的枚举
     */
    public static SenderType fromCode(Integer code) {
        for (SenderType type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown sender type code: " + code);
    }
}
